import { http } from '@/utils/http'
// 导入类型声明文件
import type { OrderPreResult, OrderCreateParams, OrderResult, OrderLogisticResult, OrderListParams, OrderListResult } from '@/types/order'

// 获取预定单API
export const getPreviewOrderAPI = () => {
  return http<OrderPreResult>({
    url: "/member/order/pre",
    method: "GET"
  })
}

//立即购买预定单API
export const getPreviewOrderNowAPI = (data : { skuId : string, count : string, addressId ?: string }) => {
  return http<OrderPreResult>({
    url: "/member/order/pre/now",
    method: "GET",
    data
  })
}


// 提交订单API
export const postOrderAPI = (data : OrderCreateParams) => {
  return http<{ id : string }>({
    url: '/member/order',
    method: "POST",
    data
  })
}

//获取订单详情API
export const getOrderDetailAPI = (id : string) => {
  return http<OrderResult>({
    url: `/member/order/${id}`,
    method: "GET"
  })
}

// 再次发起订单请求
export const getRepaedOrderDetailAPI = (id : string) => {
  return http<OrderPreResult>({
    url: `/member/order/repurchase/${id}`,
    method: "GET"
  })
}

// 模拟发货API
export const takeDeliverAPI = (id : string) => {
  return http({
    url: `/member/order/consignment/${id}`
  })
}


// 确认收获API
export const takeInDeliverAPI = (id : string) => {
  return http<OrderResult>({
    url: `/member/order/${id}/receipt`,
    method: "PUT"
  })
}


// 获取物流信息API
export const getDeliverDetailAPI = (id : string) => {
  return http<OrderLogisticResult>({
    url: `/member/order/${id}/logistics`,
    method: "GET"
  })
}

//删除订单API
export const delOrderAPI = (data : { ids : string[] }) => {
  return http({
    url: "/member/order",
    method: "DELETE",
    data
  })
}


// 取消订单
export const cancelOrderAPI = (id : string, data : { cancelReason : string }) => {
  return http({
    url: `/member/order/${id}/cancel`,
    method: "PUT",
    data
  })
}

// 获取订单列表API
export const getOrderListAPI = (data : OrderListParams) => {
  return http<OrderListResult>({
    url: "/member/order",
    method: "GET",
    data
  })
}
